package com.ts.mapper.achievement;

import com.ts.entity.TeachingResearchProject;
import org.apache.ibatis.annotations.*;

@Mapper
public interface TeachingResearchProjectMapper {

    /**
     * 存入一条教研项目成果数据并且主键返回
     */
    @Insert("INSERT INTO `tianshi-college-teacher-system-test`.ts_teaching_research_project (" +
            "achievement_type, is_first_principal, is_first_in_unit, project_name, project_number, " +
            "is_host, project_source, project_type, project_level, research_type, " +
            "subject_category, cooperation_form, total_funding, school_funding, " +
            "approval_time, conclusion_time, remark, evidence_material, " +
            "create_by, create_time, update_by, update_time" +
            ") VALUES (" +
            "#{achievementType}, #{isFirstPrincipal}, #{isFirstInUnit}, #{projectName}, #{projectNumber}, " +
            "#{isHost}, #{projectSource}, #{projectType}, #{projectLevel}, #{researchType}, " +
            "#{subjectCategory}, #{cooperationForm}, #{totalFunding}, #{schoolFunding}, " +
            "#{approvalTime}, #{conclusionTime}, #{remark}, #{evidenceMaterial}, " +
            "#{createBy}, #{createTime}, #{updateBy}, #{updateTime}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void save(TeachingResearchProject teachingResearchProject);

    /**
     * 根据ID查询教研项目
     */
    @Select("SELECT * FROM `tianshi-college-teacher-system-test`.ts_teaching_research_project WHERE id = #{id}")
    TeachingResearchProject getById(Long id);

    /**
     * 更新教研项目
     */
    @Update("UPDATE `tianshi-college-teacher-system-test`.ts_teaching_research_project SET " +
            "achievement_type = #{achievementType}, " +
            "is_first_principal = #{isFirstPrincipal}, " +
            "is_first_in_unit = #{isFirstInUnit}, " +
            "project_name = #{projectName}, " +
            "project_number = #{projectNumber}, " +
            "is_host = #{isHost}, " +
            "project_source = #{projectSource}, " +
            "project_type = #{projectType}, " +
            "project_level = #{projectLevel}, " +
            "research_type = #{researchType}, " +
            "subject_category = #{subjectCategory}, " +
            "cooperation_form = #{cooperationForm}, " +
            "total_funding = #{totalFunding}, " +
            "school_funding = #{schoolFunding}, " +
            "approval_time = #{approvalTime}, " +
            "conclusion_time = #{conclusionTime}, " +
            "remark = #{remark}, " +
            "evidence_material = #{evidenceMaterial}, " +
            "update_by = #{updateBy}, " +
            "update_time = #{updateTime} " +
            "WHERE id = #{id}")
    void update(TeachingResearchProject teachingResearchProject);

    /**
     * 根据ID删除教研项目
     */
    @Delete("DELETE FROM `tianshi-college-teacher-system-test`.ts_teaching_research_project WHERE id = #{id}")
    void delete(Long id);
}